<?php  

/**
*Form Builder & Admin Generator

*@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
*@copyright Copyright (c) 2011, marcio
*@version 1.6.5
*/

class Language 
{

	private $SessionLangName = 'Lang';
  
	private $DefaultLang = 'pl';
  
	private $message;
  
 
  
	public function __construct() 
	{
		if(!isset($_SESSION[$this -> SessionLangName]))
			$this -> setLang(); 
	}

  
	public function getLang() 
	{
		return $_SESSION[$this -> SessionLangName];
	}
  
  
	public function setLang($lang = '') 
	{
	
		$language = (isset($lang) && !empty($lang)) ? $lang : $this -> DefaultLang;
  
		if(!isset($_SESSION[$this -> SessionLangName])) 
		{
			$_SESSION[$this -> SessionLangName] = $language;
		}
	  
		else 
		{
			unset($_SESSION[$this -> SessionLangName]);
			$_SESSION[$this -> SessionLangName] = $language;
		}
	  
	  return $language;
	}
  
  
	private function LanguageFileExists($file, $type = 'libs') 
	{
     
		if(file_exists('i18n/'.$type.'/'.$file.'.php')) 
		{
			$message = require_once('i18n/'.$type.'/'.$file.'.php');
			return $message;
		}  
	 
		return false;
	}
  
  
	public function setLangMessage($class, $type = 'libs') 
	{
      if($msg = $this -> LanguageFileExists($class, $type)) 
	       $this -> message = $msg[$this -> getLang()];
	}
  
  
	public function get($key, $vkey) 
	{
		return $this -> message[$key][$vkey];
	}
  
  
	public function get_array()
	{
		return $this -> message;
	}
	
  
	public function __get($key) 
	{
		return $this -> message[$key];
	}

}

?>